// This file is required by the index.html file and will
// be executed in the renderer process for that window.
// No Node.js APIs are available in this process because
// `nodeIntegration` is turned off. Use `preload.js` to
// selectively enable features needed in the rendering
// process.
const { ipcRenderer } = require('electron')

window.addEventListener('DOMContentLoaded', () => {
    setTimeout(() => {
        ipcRenderer.send('checkForUpdate')
    }, 1000)

    ipcRenderer.on('message', (event, text) => {
        document.getElementById('tips').innerHTML = text
    })

    ipcRenderer.on('downloadProgress', (event, processObj) => {
        // TODO
    })

    ipcRenderer.on('canUpdateNow', () => {
        document.getElementById('install').addEventListener('click', install)
        function install() {
            ipcRenderer.send('execUpdateNow')
        }
    })
})
